/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：NetBattle.java <br>
 * 创建时间：2015年5月1日 下午1:46:06 <br>
 * 所属项目：GmudEX <br>
 * @author 12548
 */
package lostland.gmud.exv2.battle.proc.holder;

import com.lidroid.xutils.http.RequestParams;

import lostland.general.network.GmudHttp;
import lostland.general.network.GmudRestUrl;
import lostland.gmud.exv2.battle.BattleScreen;
import lostland.gmud.exv2.battle.netbattle.NetworkMode;
import lostland.gmud.exv2.ui.NotificationScreen;

/**
 * 类名：NetBattle <br>
 * 说明：
 *
 * @author 12548
 */
public class NetBattle extends BattleHolder {

	/**
	 *
	 */
	public NetBattle() {
		// TODO 自动生成的构造函数存根
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.battle.proc.holder.BattleHolder#updato()
	 */
	@Override
	void updato() {
		boolean b = BattleScreen.getInstance().networkMode == NetworkMode.HOST;
		if (b) {
			final RequestParams pr = GmudHttp.initBattleParams();
			pr.addBodyParameter("result", String.valueOf(battle_stat + 1));
			new GmudHttp().postBackground(GmudRestUrl.HostFinish, pr, null);
		}


		BattleScreen.getInstance().networkMode = NetworkMode.LOCAL;
		switch (battle_stat) {
			case BattleHolder.BATTLE_PLAYER1_WIN:
				if (b) {
					win();
				} else {
					lose();
				}
				break;
			case BattleHolder.BATTLE_PLAYER2_WIN:
				if (!b) {
					win();
				} else {
					lose();
				}
				break;
			case BattleHolder.BATTLE_RUNAWAY:
				if (!b) {
					win();
				} else {
					lose();
				}
				break;
		}
	}

	void win() {
		getGame().popToRootScreen();
		new NotificationScreen("你胜利了！").pushToGame();
	}

	void lose() {
		getGame().popToRootScreen();
		new NotificationScreen("你失败了！").pushToGame();
	}

}
